package com.aistar.user.exception;


import com.aistar.common.vo.Result;
import com.aistar.common.vo.StatusCode;
import io.jsonwebtoken.ExpiredJwtException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by js on 2019/7/1.
 */
//@ControllerAdvice
public class MyExceptionHandle {

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Result defaultExceptionHandler(HttpServletRequest request, HttpServletResponse response,Exception e)throws IOException{
        if (e instanceof ExpiredJwtException){
            return new Result(false, StatusCode.ACCESSERROR,"token失效 请重新登录");
        }else {
            return new Result(false,StatusCode.ERROR,"错误");
        }
    }

}
